#-----------------------------------
# Name: Chris Spooner
# Project Madlibs.py
# Period: 1
# Start Date: 9/18/2013
# Last Revision Date: 9/18/2013
# Version: 1.0.0
#----------------------------
import os

statelist = ["Alabama",
             "Alaska",
             "Arizona",
             "Arkansas",
             "California",
             "Colorado",
             "Connecticut",
             "Delaware",
             "Florida",	
             "Georgia",
             "Hawaii",	    
             "Idaho",
             "Illinois",	
             "Indiana",	
             "Iowa",	
             "Kansas",
             "Kentucky",	
             "Louisiana",	
             "Maine",
             "Maryland",
             "Massachusetts",	
             "Michigan",
             "Minnesota",
             "Mississippi",
             "Missouri",
             "Montana",
             "Nebraska",
             "Nevada",
             "New Hampshire",
             "New Jersey",
             "New Mexico",
             "New York",
             "North Carolina",	
             "North Dakota",
             "Ohio",
             "Oklahoma",
             "Oregon",	
             "Pennsylvania",	
             "Rhode Island",
             "South Carolina",
             "South Dakota",
             "Tennessee",
             "Texas",
             "Utah",
             "Vermont",	
             "Virginia",
             "Washington",	
             "West Virginia",
             "Wisconsin",
             "Wyoming",]
 
swearList = [  "dumb",
               "stupid",
               "retard"
               "Jack sunglasses emoji Shock poop swastika",
               "cunt",
               "muff",
               "vajay",
               "vagina",
               "penis" ,
               "dick" ,
               "cock" ,
               "pussy" ,
               "puss" ,
               "poon" ,
               "shlong", 
               "bepis" ,
               "nigger" ,
               "nigga" ,
               "bitch" ,
               "swastika",
               "poop" ,
               "scat" ,
               "niga" ,
               "niger" ,
               "fetus" ,
               "fuck" ,
               "shit" ,
               "balls" ,
               "hitler" ,
               "shitler" ,
               "piss" ,
               "jizz" ,
               "anal",
               "butt stuff",
               "ass",
               "dong",
               "masturbate",
               "masturbation",
               "asshole",
               "damn",
               "god dammit",
               "god damn it",
               "dammit",
               "micropenis",
               "fuckton",
               "bad touch",
               "pedofile",
               "vag",
               "whore",
               "slut",
               "weed",
               "drugs",
               "crack",
               "coke",
               "meth",
               "crank",              
               "speed",
               "molly",
               "x",
               "ecstasy",
               "shrooms",
               "nazi",
               "BBW",
               "tranny",
               "shemale",
               "ladyboy",
               "bondage",
               "smut",
               "fetish",
               "tits",
               "boobs",
               "jugs",
               "butthole",              
               "squirt",
               "marijuana",
               "dro",
               "bong",
               "joint",
               "blunt",
               "bowl",
               "pipe",
               "vaporizer",
               "vape",
               "porn star",
               "dummy",
               "idiot",
               "fart",
               "drunk",
               "alcohol",
               "wasted",
               "fucked up", 
               "heroin",
               "cigarette",
               "cigs",
               "lighter",
               "buzzed",
               "buzz",
               "high",
               "ganja",
               "dabs",
               "motherfucker",
               "milf",
               "dildo",
               "vibrator",
               "pocket pussy",
               "fleshlight",
               "faggot",
               "fag",
               "rectum",
               "addy",
               "adderall",
               "vicodin" ,
               "vicodine",
               "codine",
               "syrup",
               "clonopin",
               "klonopin",
               "benodryl",
               "ritalin" ,
               "morphine",
               "dmt",
               "salvia",
               "douche",
               "kedamine",
               "peen",
               "spic",
               "ching chong",
               "bing bong",
               "turnt up",
               "turn up",
               "porch monkey",
               "gook",
               "chink",
               "slope",
               "rape",
               "rapist",
               "fetal",
               "ejaculate"]
             
bgColor = '0'
txtColor = 'F'

colors = [   "black",
             "blue",
             "green",
             "bright white",
             "light red",
             "red"]

def getMenuOption(maxOptions):
    option = ""
    goodOption = False
    while not goodOption:
        option = raw_input("Enter a number or S or Q> ")
        option = option.upper()
        if option == 'S':
            goodOption = True
        elif option == 'Q' :
            goodOption = True
        elif option == "":
            pass
        else:
            isNum = True
            for character in option:
                if character not in "0123456789":
                    isNum = False
            if isNum:
                if int(option) <= 0:
                    isNum = False
                elif int(option) > maxOptions:
                    isNum = False
            if isNum:
                goodOption = True
            else:
                print "What did you do!"
        if not goodOption:
            print "You done goofed, try again. "
    return option

 
def menu():
    print "Welcome to Madlibs"
    print "Please Select an Option:"
    print " [1] Math Teacher"
    print " [2] My Little Friend"
    print " [3] Random"
    print " [S] Settings"
    print " [Q] Quit"
    option = getMenuOption(3)
    return option
    
def getState(prompt):
    word = ""
    goodState = False
    while not goodState:
        word = raw_input(prompt)
        word = word.title()
        if word in statelist:
            goodState = True
        else:
            print "Not a State"
        if not goodState:
            print "Try again"
    return word

def getWord(prompt):
    word = ""
    goodWord = False
    while not goodWord:
        word = raw_input(prompt)
        if word.lower() not in swearList:
            isNum = False
            for digit in word:
                if digit in "0123456789":
                    isNum = True
            if not isNum:
                goodWord = True
            else:
                print "Words don't have digits!"
        else:
            print "Watch your language!"
        if not goodWord:
            print "Try again!"
    return word

def getNumber(prompt, min = "", max = ""):
        num = ""
        goodNumber = False
        while not goodNumber:
            num = raw_input(prompt)
            isNum = True
            for digit in num:
                if digit not in ".0123456789":
                    isNum = False
            if isNum:
                if min != "":
                    if float(num) < min:
                        isNum = False
                if max != "":
                    if float(num) > max:
                        isNum = False
            if isNum:
                goodNumber = True
            else:
                print "Enter a real number, I dont have all day!"
        return num
                    
def getColor(prompt):
    
    opt = ""
    goodColor = False
    while not goodColor:
        opt = raw_input(prompt)
        if opt.lower() in colors:
            goodColor = True
        else:
            print opt + " is not a valid color, "
    if opt == "black":
        color = '0'
    elif opt == 'blue':
        color = '1'
    elif opt == 'green':
        color = '2'
    elif opt == 'bright white':
        color = 'F'
    elif opt == 'light red':
        color = 'C'
    elif opt == 'red':
        color = '4'
    return color
        
            
                    
def story3():
    man = getWord("Enter the man's name: ")
    state = getState("Enter a state: ")
    creature = getWord("Enter Mythical Creature: ")
    creature2 = getWord("Enter a second Mythical Creature: ")
    cop = getWord("Enter a cops name: ")
    female = getWord("Enter a female name: ")
    number = getNumber("Enter a number: ", 0)
    story = ""
    story += "It was a warm day in " + state + " and " + man
    story += " was making his way home when the " + creature + " emerged from the ground."
    story += " It then proceeded to go on a rampage destroying everything. "
    story += man + " ran away from the creature but then a " + creature2 + " arose from behind a building and started attacking the other creature. "
    story += "As the the two creatures started destroying the town, the cops began removing the citizens. "
    story += "Sergeant " + cop + " said, 'Move along everyone, this happens all the time' "
    story += "Then " + female + " asked, 'What do you mean it happens often?' "
    story += "'Well this happened about " + number + " hours ago', said the cop."
    print
    print formatString(story, 80, 15)
    print
    
    
def story2():
    man = getWord("Enter a man's name: ")
    name = getWord("Enter a male animal name: ")
    age = getNumber("Enter a number: ", 0)
    animal = getWord("Enter an animal: ")
    female = getWord("Enter a female name: ")
    officer = getWord("Enter a cop's name: ")
    hospital = getWord("Enter a hospital's name without saying hospital: ")
    story = ""
    story += "My name is " + man + ". "
    story += "I have a " + animal + " named " + name + ". "
    story += name + " is "
    story += age + " years old. "
    story += name + " has been in the family ever since he was born. "
    story += "The other day " + name + " got into my cocaine stash in my room. "
    story += name + " then went on a rampage. "
    story += "My sister, " + female + ", was in the way of " + name +  " and was hurt pretty bad, I rushed over to check on her. "
    story += female + " was hurt pretty bad, she had broken ribs and a broken nose. "
    story += "I took her to the " + hospital + " hospital where she was admitted. "
    story += "Then police chief " + officer + " walked up to me and asked, 'Is this your " +  animal + ", because we have to kill it.' "
    story += "I cried then nodded, 'Fine, whatever, it got into my drugs so it needs to die.'"
    print
    print formatString(story, 80, 15)
    print
    
    
def story1():
    place = getWord("Enter a town: ")
    name = getWord("Enter a male name: ")
    school = getWord("Enter a school name: ")
    cop = getWord("Enter a cop's name: ")
    date = getNumber("Enter a number 1-30: ", 0, 30)
    store = getWord("Enter a store name: ")
    goods = getWord("Enter an item sold at store: ")
    story = "  It was a warm day in "
    story += place
    story += " and the math teacher, "
    story += name
    story += ", had just had his daily dose of drugs and coffee."
    story += " He proceeded to make his way to "
    story += school + ". "
    story += name + " decided to stop at " + store + " when a man came to him and said, 'Hey, you know what day it is? "
    story += name + " said 'I believe that its the " + date + ", I'm in rather a hurry, goodbye."
    story += " And with that he left the store with his " + goods + ". Before he reached his car, Sergeant "
    story += cop + " pulled into the parking lot and parked right next to " + name + "'s car. "
    story += name + " froze, he was still messed up from the drugs and he didn't want to be near a cop. "
    story += "Sergeant " + cop + " got out and walk towards " + name + ", recognizing him as the new one he said, 'Hello, wonderful day.' "
    story += name + " suddenly went mad, he punched the cop in the face and the ran to his car, drove back and hit the cop that was just getting up with his bumper. "
    story += name + " then drove off into the distance never to be seen again"
    print
    print formatString(story, 80, 15)
    print


def formatString(s, width, buff):
    ns = ""
    count = 0
    for c in s:
        count += 1
        if c == " ":
            if count >= width - buff:
                ns += "\n"
                count = 0
            else:
                ns += c
        else:
            ns += c
    return ns
    

def settings():
    print "Colors available: "
    for c in colors:
        print c + ", ",
    print
    txtColor = getColor("Enter Text Color: ")
    bgColor = getColor("Enter Background Color: ")
    if txtColor != bgColor:
        os.system("color " + bgColor + txtColor)
    
def run():
    choice = ""
    while choice != 'Q':
        choice = menu()
        if choice == '1':
            story1()
        elif choice == '2':
            story2()
        elif choice == '3':
            story3()
        elif choice == 'S':
            settings()
        elif choice == 'Q':
            print " Goodbye"
            os.system("color " + bgColor + txtColor)
            raw_input("Press enter to exit")
        else:
            print "Oh Shit! You broke it!"
    
run()   